package com.nervenets.template.controller.user.params;

import com.anji.captcha.model.vo.CaptchaVO;
import com.nervenets.general.Global;
import com.nervenets.general.utils.AESUtils;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.SuperBuilder;
import org.apache.commons.lang3.StringUtils;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import java.io.Serializable;

@Setter
@Getter
@AllArgsConstructor
@NoArgsConstructor
@SuperBuilder
public class MobileLoginParams implements Serializable {
    @ApiModelProperty(value = "手机号", required = true)
    @Pattern(regexp = Global.RegExp.MOBILE, message = "请输入正确的手机号码")
    private String username;
    @ApiModelProperty(value = "密码", required = true)
    @NotBlank
    private String password;
    @ApiModelProperty(value = "图形验证数据", required = true)
    @NotNull
    private CaptchaVO captcha;

    public String decryptPassword() {
        return StringUtils.trim(AESUtils.decryptString(this.password));
    }
}
